package com.demo.arch.datapulsedemo.v3_reliable.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import jakarta.annotation.PostConstruct;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * 存储配置
 * 
 * 初始化任务状态存储目录
 * 
 * @author DataPulse Team
 */
@Slf4j
@Configuration
public class StorageConfig {

  private static final String STORAGE_DIR = "/tmp/datapulse";

  @PostConstruct
  public void initStorageDirectories() {
    try {
      // 创建上下文存储目录
      Path contextsDir = Paths.get(STORAGE_DIR, "contexts");
      if (!Files.exists(contextsDir)) {
        Files.createDirectories(contextsDir);
        log.info("创建任务状态存储目录: {}", contextsDir);
      }

      // 创建报表存储目录
      Path reportsDir = Paths.get(STORAGE_DIR, "reports");
      if (!Files.exists(reportsDir)) {
        Files.createDirectories(reportsDir);
        log.info("创建报表存储目录: {}", reportsDir);
      }

    } catch (Exception e) {
      log.warn("无法创建存储目录，可能影响应用功能：{}", e.getMessage());
    }
  }
}
